﻿@using DTcms.Common;
@using DTcms.Model;
@{
   Layout = "~/Areas/admin/Views/Shared/_LayoutEdit.cshtml";
   ViewBag.Title = "order_edit";
   DTcms.Model.orders m = ViewData["model"] as DTcms.Model.orders;
   DTcms.Model.users userModel = ViewData["userModel"] as DTcms.Model.users;
   DTcms.Model.user_groups groupModel = ViewData["groupModel"] as DTcms.Model.user_groups;
}
@section Scripts{
<script type="text/javascript">
   $(function () {
      $("#btnConfirm").click(function () { OrderConfirm(); });   //确认订单
      $("#btnPayment").click(function () { OrderPayment(); });   //确认付款
      $("#btnExpress").click(function () { OrderExpress(); });   //确认发货
      $("#btnComplete").click(function () { OrderComplete(); }); //完成订单
      $("#btnCancel").click(function () { OrderCancel(); });     //取消订单
      $("#btnInvalid").click(function () { OrderInvalid(); });   //作废订单
      $("#btnPrint").click(function () { OrderPrint(); });       //打印订单

      $("#btnEditAcceptInfo").click(function () { EditAcceptInfo(); }); //修改收货信息
      $("#btnEditRemark").click(function () { EditOrderRemark(); });    //修改订单备注
      $("#btnEditRealAmount").click(function () { EditRealAmount(); }); //修改商品总金额
      $("#btnEditExpressFee").click(function () { EditExpressFee(); }); //修改配送费用
      $("#btnEditPaymentFee").click(function () { EditPaymentFee(); }); //修改支付手续费
      $("#btnEditInvoiceTaxes").click(function () { EditInvoiceTaxes(); }); //修改发票税金
   });
   //确认订单
   function OrderConfirm() {
      var winDialog = top.dialog({
         title: '提示',
         content: '确认订单后将无法修改金额，确认要继续吗？',
         okValue: '确定',
         ok: function () {
            var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "order_confirm" };
            //发送AJAX请求
            sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
            return false;
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }
   //确认付款
   function OrderPayment() {
      var winDialog = top.dialog({
         title: '提示',
         content: '操作提示信息：<br />1、该订单使用在线支付方式，付款成功后自动确认；<br />2、如客户确实已打款而没有自动确认可使用该功能；<br />3、确认付款后无法修改金额，确认要继续吗？',
         okValue: '确定',
         ok: function () {
            var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "order_payment" };
            //发送AJAX请求
            sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
            return false;
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }
   //确认发货
   function OrderExpress() {
      var winDialog = top.dialog({
         title: '提示',
         url: '../dialog/dialog_express/index?order_no=' + $("#spanOrderNo").text(),
         width: 450,
         data: window //传入当前窗口
      }).showModal();
   }
   //完成订单
   function OrderComplete() {
      var winDialog = top.dialog({
         title: '完成订单',
         content: '订单完成后，订单处理完毕，确认要继续吗？',
         button: [{
            value: '确定',
            callback: function () {
               var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "order_complete" };
               //发送AJAX请求
               sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
               return false;
            },
            autofocus: true
         }, {
            value: '取消',
            callback: function () { }
         }]
      }).showModal();
   }
   //取消订单
   function OrderCancel() {
      var winDialog = top.dialog({
         title: '取消订单',
         content: '操作提示信息：<br />1、匿名用户，请线下与客户沟通；<br />2、会员用户，自动检测退还金额或积分到账户；<br />3、请单击相应按钮继续下一步操作！',
         button: [{
            value: '检测退还',
            callback: function () {
               var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "order_cancel", "check_revert": 1 };
               //发送AJAX请求
               sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
               return false;
            },
            autofocus: true
         }, {
            value: '直接取消',
            callback: function () {
               var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "order_cancel", "check_revert": 0 };
               //发送AJAX请求
               sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
               return false;
            }
         }, {
            value: '关闭',
            callback: function () { }
         }]
      }).showModal();
   }
   //作废订单
   function OrderInvalid() {
      var winDialog = top.dialog({
         title: '取消订单',
         content: '操作提示信息：<br />1、匿名用户，请线下与客户沟通；<br />2、会员用户，自动检测退还金额或积分到账户；<br />3、请单击相应按钮继续下一步操作！',
         button: [{
            value: '检测退还',
            callback: function () {
               var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "order_invalid", "check_revert": 1 };
               //发送AJAX请求
               sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
               return false;
            },
            autofocus: true
         }, {
            value: '直接作废',
            callback: function () {
               var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "order_invalid", "check_revert": 0 };
               //发送AJAX请求
               sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
               return false;
            }
         }, {
            value: '关闭',
            callback: function () { }
         }]
      }).showModal();
   }
   //打印订单
   function OrderPrint() {
      var winDialog = top.dialog({
         title: '打印订单',
         url: '../dialog/dialog_print/index?order_no=' + $("#spanOrderNo").text(),
         width: 850
      }).showModal();
   }
   //修改收货信息
   function EditAcceptInfo() {
      var winDialog = top.dialog({
         title: '修改收货信息',
         url: '../dialog/dialog_accept/index',
         width: 550,
         height: 320,
         data: window //传入当前窗口
      }).showModal();
   }
   //修改订单备注
   function EditOrderRemark() {
      var winDialog = top.dialog({
         title: '订单备注',
         content: '<textarea id="txtOrderRemark" name="txtOrderRemark" rows="2" cols="20" class="input">' + $("#divRemark").html() + '</textarea>',
         okValue: '确定',
         ok: function () {
            var remark = $("#txtOrderRemark", parent.document).val();
            if (remark == "") {
               top.dialog({
                  title: '提示',
                  content: '对不起，请输入订单备注内容！',
                  okValue: '确定',
                  ok: function () { }
               }).showModal(winDialog);
               return false;
            }
            var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "edit_order_remark", "remark": remark };
            //发送AJAX请求
            sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
            return false;
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }

   //修改商品总金额
   function EditRealAmount() {
      var winDialog = top.dialog({
         title: '请修改商品总金额',
         content: '<input id="txtDialogAmount" type="text" value="' + $("#spanRealAmountValue").text() + '" class="input" />',
         okValue: '确定',
         ok: function () {
            var amount = $("#txtDialogAmount", parent.document).val();
            if (!checkIsMoney(amount)) {
               top.dialog({
                  title: '提示',
                  content: '对不起，请输入正确的商品金额！',
                  okValue: '确定',
                  ok: function () { }
               }).showModal(winDialog);
               return false;
            }
            var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "edit_real_amount", "real_amount": amount };
            //发送AJAX请求
            sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
            return false;
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }
   //修改配送费用
   function EditExpressFee() {
      var winDialog = top.dialog({
         title: '请修改配送费用',
         content: '<input id="txtDialogAmount" type="text" value="' + $("#spanExpressFeeValue").text() + '" class="input" />',
         okValue: '确定',
         ok: function () {
            var amount = $("#txtDialogAmount", parent.document).val();
            if (!checkIsMoney(amount)) {
               top.dialog({
                  title: '提示',
                  content: '对不起，请输入正确的配送金额！',
                  okValue: '确定',
                  ok: function () { }
               }).showModal(winDialog);
               return false;
            }
            var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "edit_express_fee", "express_fee": amount };
            //发送AJAX请求
            sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
            return false;
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }
   //修改手续费用
   function EditPaymentFee() {
      var winDialog = top.dialog({
         title: '请修改支付手续费用',
         content: '<input id="txtDialogAmount" type="text" value="' + $("#spanPaymentFeeValue").text() + '" class="input" />',
         okValue: '确定',
         ok: function () {
            var amount = $("#txtDialogAmount", parent.document).val();
            if (!checkIsMoney(amount)) {
               top.dialog({
                  title: '提示',
                  content: '对不起，请输入正确的手续费用！',
                  okValue: '确定',
                  ok: function () { }
               }).showModal(winDialog);
               return false;
            }
            var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "edit_payment_fee", "payment_fee": amount };
            //发送AJAX请求
            sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
            return false;
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }
   //修改税金费用
   function EditInvoiceTaxes() {
      var winDialog = top.dialog({
         title: '请修改发票税金费用',
         content: '<input id="txtDialogAmount" type="text" value="' + $("#spanInvoiceTaxesValue").text() + '" class="input" />',
         okValue: '确定',
         ok: function () {
            var amount = $("#txtDialogAmount", parent.document).val();
            if (!checkIsMoney(amount)) {
               top.dialog({
                  title: '提示',
                  content: '对不起，请输入正确的税金费用！',
                  okValue: '确定',
                  ok: function () { }
               }).showModal(winDialog);
               return false;
            }
            var postData = { "order_no": $("#spanOrderNo").text(), "edit_type": "edit_invoice_taxes", "invoice_taxes": amount };
            //发送AJAX请求
            sendAjaxUrl(winDialog, postData, "/tools/admin_ajax.ashx?action=edit_order_status");
            return false;
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }

   //=================================工具类的JS函数====================================
   //检查是否货币格式
   function checkIsMoney(val) {
      var regtxt = /^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/;
      if (!regtxt.test(val)) {
         return false;
      }
      return true;
   }
   //发送AJAX请求
   function sendAjaxUrl(winObj, postData, sendUrl) {
      $.ajax({
         type: "post",
         url: sendUrl,
         data: postData,
         dataType: "json",
         error: function (XMLHttpRequest, textStatus, errorThrown) {
            top.dialog({
               title: '提示',
               content: '尝试发送失败，错误信息：' + errorThrown,
               okValue: '确定',
               ok: function () { }
            }).showModal(winObj);
         },
         success: function (data, textStatus) {
            if (data.status == 1) {
               winObj.close().remove();
               var d = dialog({ content: data.msg }).show();
               setTimeout(function () {
                  d.close().remove();
                  location.reload(); //刷新页面
               }, 2000);
            } else {
               top.dialog({
                  title: '提示',
                  content: '错误提示：' + data.msg,
                  okValue: '确定',
                  ok: function () { }
               }).showModal(winObj);
            }
         }
      });
   }
</script>   
}
<form id="form1" method="post" action="SubmitSave?id=@ViewBag.Id">
<!--导航栏-->
<div class="location">
  <a href="../order_list/index" class="back"><i class="iconfont icon-up"></i><span>返回列表页</span></a>
  <a href="../../center/index"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <a href="../order_list/index"><span>订单管理</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>订单详细</span>
</div>
<div class="line10"></div>
<!--/导航栏-->

<!--内容-->
<div id="floatHead" class="content-tab-wrap">
  <div class="content-tab">
    <div class="content-tab-ul-wrap">
      <ul>
        <li><a class="selected" href="javascript:;">订单详细信息</a></li>
      </ul>
    </div>
  </div>
</div>

<div class="tab-content">
  <dl>
    <dd style="margin-left:50px;text-align:center;">
      <div class="order-flow" style="width:560px">
        @if (m.status < 4)
        { 
        <div class="order-flow-left">
          <a class="order-flow-input">生成</a>
          <span><p class="name">订单已生成</p><p>@m.add_time</p></span>
        </div>
        if (m.payment_status == 1)
          {
        <div class="order-flow-wait">
          <a class="order-flow-input">付款</a>
          <span><p class="name">等待付款</p></span>
        </div>
        }
        else if (m.payment_status == 2)
        {
        <div class="order-flow-arrive">
          <a class="order-flow-input">付款</a>
          <span><p class="name">已付款</p><p>@m.payment_time</p></span>
        </div>
        }
        if (m.payment_status == 0 && m.status == 1)
        {
        <div class="order-flow-wait">
           <a class="order-flow-input">确认</a>
           <span><p class="name">等待确认</p></span>
        </div>
        }
        else if (m.payment_status == 0 && m.status > 1)
        {
        <div class="order-flow-arrive">
          <a class="order-flow-input">确认</a>
          <span><p class="name">已确认</p><p>@m.confirm_time</p></span>
        </div>
        }
        if (m.express_status == 1)
        {
        <div class="order-flow-wait">
          <a class="order-flow-input">发货</a>
          <span><p class="name">等待发货</p></span>
        </div>
        }
        else if (m.express_status == 2)
        {
        <div class="order-flow-arrive">
          <a class="order-flow-input">发货</a>
          <span><p class="name">已发货</p><p>@m.express_time</p></span>
         </div>
         }
         if (m.status == 3)
         {
         <div class="order-flow-right-arrive">
           <a class="order-flow-input">完成</a>
           <span><p class="name">订单完成</p><p>@m.complete_time</p></span>
         </div>
         }
         else
         {
         <div class="order-flow-right-wait">
           <a class="order-flow-input">完成</a>
           <span><p class="name">等待完成</p></span>
         </div>
         }
         }
        else if (m.status == 4)
        {
          <div style="text-align:center;line-height:30px; font-size:20px; color:Red;">该订单已取消</div>
         }
         else if (m.status == 5)
         {
          <div style="text-align:center;line-height:30px; font-size:20px; color:Red;">该订单已作废</div>
        }
      </div>
    </dd>
  </dl>
  <dl>
    <dt>订单号</dt>
    <dd><span id="spanOrderNo">@m.order_no</span></dd>
  </dl>

  <dl>
    <dt>商品列表</dt>
    <dd>
      <div class="table-container">
        <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
        <thead>
          <tr>
            <th style="text-align:left;">商品信息</th>
            <th width="8%">销售价</th>
            <th width="8%">优惠价</th>
            <th width="8%">积分</th>
            <th width="8%">数量</th>
            <th width="12%">金额合计</th>
            <th width="8%">积分合计</th>
          </tr>
        </thead>
        <tbody>
@if(m.order_goods != null){
   foreach(DTcms.Model.order_goods item in m.order_goods){
          <tr class="td_c">
            <td style="text-align:left;white-space:inherit;word-break:break-all;line-height:20px;">
              @item.goods_title
              @if(item.spec_text != ""){
                 <br />
              }
              else {
                 @item.spec_text
              }
            </td>
            <td>@item.goods_price</td>
            <td>@item.real_price</td>
            <td>@item.point</td>
            <td>@item.quantity</td>
            <td>@(item.real_price * item.quantity)</td>
            <td>@(item.point * item.quantity)</td>
          </tr>
   }
}
        </tbody>
        </table>
      </div>
    </dd>
  </dl>

  <dl>
    <dt>收货信息</dt>
    <dd>
      <div class="table-container">
        <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
        <tr>
          <th width="20%">收件人</th>
          <td>
            <div class="position">
              <span id="spanAcceptName">@m.accept_name</span>
              <input id="btnEditAcceptInfo" runat="server" visible="false" type="button" class="ibtn" value="修改" />
            </div>
          </td>
        </tr>
        <tr>
          <th>发货地址</th>
          <td><span id="spanArea">@m.area</span> <span id="spanAddress">@m.address</span></td>
        </tr>
        <tr>
          <th>邮政编码</th>
          <td><span id="spanPostCode">@m.post_code</span></td>
        </tr>
        <tr>
          <th>手机</th>
          <td><span id="spanMobile">@m.mobile</span></td>
        </tr>
        <tr>
          <th>电话</th>
          <td><span id="spanTelphone">@m.telphone</span></td>
        </tr>
        <tr>
          <th>邮箱</th>
          <td><span id="spanEmail">@m.email</span></td>
        </tr>
        </table>
      </div>
    </dd>
  </dl>
@if(groupModel != null){
  <dl id="dlUserInfo">
    <dt>会员信息</dt>
    <dd>
      <div class="table-container">
        <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
        <tr>
          <th width="20%">会员账户</th>
          <td><label id="lbUserName">@userModel.user_name</label></td>
        </tr>
        <tr>
          <th>会员组别</th>
          <td><label id="lbUserGroup">@groupModel.title</label></td>
        </tr>
        <tr>
          <th>购物折扣</th>
          <td><label id="lbUserDiscount">@groupModel.discount %</label></td>
        </tr>
        <tr>
          <th>账户余额</th>
          <td><label id="lbUserAmount">@userModel.amount 元</label></td>
        </tr>
        <tr>
          <th>账户积分</th>
          <td><label id="lbUserPoint">@userModel.point 元</label></td>
        </tr>
        </table>
      </div>
    </dd>
  </dl>
}
  <dl>
    <dt>支付配送</dt>
    <dd>
      <div class="table-container">
        <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
        <tr>
          <th width="20%">支付方式</th>
          <td>@(new DTcms.BLL.payment().GetTitle(m.payment_id))</td>
        </tr>
        <tr>
          <th>配送方式</th>
          <td>@(new DTcms.BLL.express().GetTitle(m.express_id))</td>
        </tr>
        <tr>
          <th>是否开具发票</th>
          <td>@(m.is_invoice == 1 ? "是" : "否")</td>
        </tr>
        @if (m.is_invoice == 1) {
        <tr>
          <th>发票抬头</th>
          <td>@m.invoice_title</td>
        </tr>
        }
        <tr>
          <th>用户留言</th>
          <td>@m.message</td>
        </tr>
        <tr>
          <th valign="top">订单备注</th>
          <td>
            <div class="position">
              <div id="divRemark">@m.remark</div>
              <input id="btnEditRemark" runat="server" visible="false" type="button" class="ibtn" value="修改" />
            </div>
          </td>
        </tr>
        @if (m.express_status == 2 && m.express_no.Length > 0) {
        <tr>
          <th>物流单号</th>
          <td>@m.express_no</td>
        </tr>
        }
        </table>
      </div>
    </dd>
  </dl>
  <dl>
    <dt>订单统计</dt>
    <dd>
      <div class="table-container">
        <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
        <tr>
          <th width="20%">商品总金额</th>
          <td>
            <div class="position">
              <span id="spanRealAmountValue">@m.real_amount</span> 元
              <input id="btnEditRealAmount" runat="server" visible="false" type="button" class="ibtn" value="调价" />
            </div>
          </td>
        </tr>
        <tr>
          <th>配送费用</th>
          <td>
            <div class="position">
              <span id="spanExpressFeeValue">@m.express_fee</span> 元
              <input id="btnEditExpressFee" runat="server" visible="false" type="button" class="ibtn" value="调价" />
            </div>
          </td>
        </tr>
        <tr>
          <th>支付手续费</th>
          <td>
            <div class="position">
              <span id="spanPaymentFeeValue">@m.payment_fee</span> 元
              <input id="btnEditPaymentFee" runat="server" visible="false" type="button" class="ibtn" value="调价" />
            </div>
          </td>
        </tr>
        <tr>
          <th>发票税金</th>
          <td>
            <div class="position">
              <span id="spanInvoiceTaxesValue">@m.invoice_taxes</span> 元
              <input id="btnEditInvoiceTaxes" runat="server" visible="false" type="button" class="ibtn" value="调价" />
            </div>
          </td>
        </tr>
        <tr>
          <th>积分总计</th>
          <td>
            <div class="position">
              @(m.point > 0 ? "+" + m.point.ToString() : m.point.ToString()) 分
            </div>
          </td>
        </tr>
        <tr>
          <th>订单总金额</th>
          <td>@m.order_amount 元</td>
        </tr>
        </table>
      </div>
    </dd>
  </dl>
</div>
<!--/内容-->


<!--工具栏-->
<div class="page-footer">
  <div class="btn-wrap">
    <input id="btnConfirm" runat="server" visible="false" type="button" value="确认订单" class="btn" />
    <input id="btnPayment" runat="server" visible="false" type="button" value="确认付款" class="btn" />
    <input id="btnExpress" runat="server" visible="false" type="button" value="确认发货" class="btn" />
    <input id="btnComplete" runat="server" visible="false" type="button" value="完成订单" class="btn" />
    <input id="btnCancel" runat="server" visible="false" type="button" value="取消订单" class="btn green" />
    <input id="btnInvalid" runat="server" visible="false" type="button" value="作废订单" class="btn green" />
    <input id="btnPrint" type="button" value="打印订单" class="btn violet" />
    <input id="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);" />
  </div>
</div>
<!--/工具栏-->

</form>
